fieldset, div {
display: flex;
border: 1px solid;
}
foo
bar
foo
bar
5 个解决方案
#1
84
According to Bug 984869 - display: flex doesn't work for button elements,
根据Bug 984869 - display: flex不适用于按钮元素,
is not implementable (by browsers) in pure CSS, so they are a bit of a black box, from the perspective of CSS. This means that they don't necessarily react in the same way that e.g. a
would.
This isn't specific to flexbox -- e.g. we don't render scrollbars if you put overflow:scroll on a button, and we don't render it as a table if you put display:table on it.
Stepping back even further, this isn't specific to . Consider
and
which also have special rendering behavior:
退一步,这并不是特定于
data:text/html,
abc
def
In these cases, Chrome agrees with us and disregards the flex display mode. (as revealed by the fact that "abc" and "def" end up being stacked vertically). The fact that they happen to do what you're expecting on is likely just due to an implementation detail.
In Gecko's button implementation, we hardcode (and
, and
) as having a specific frame class (and hence, a specific way of laying out the child elements), regardless of the display property.
在Gecko的按钮实现中,我们硬编码
If you want to reliably have the children reliably arranged in a particular layout mode in a cross-browser fashion, your best bet is to use a wrapper-div inside the button, just as you would need to inside of a
Therefore, that bug was marked as "resolved invalid".
因此,该错误被标记为“已解析无效”。
There is also Bug 1047590 - display: flex; doesn't work in
, currently "unconfirmed".
还有Bug 1047590 - display: flex;未在
中工作,当前为“未确认”。
Good news: Firefox 46+ implements Flexbox for
. See bug 1230207.
好消息:Firefox 46+为
实现了Flexbox。看到错误1230207。
#2
8
I find out this might be a bug on Chrome and Firefox where legend and fieldset are replaced elements.
我发现这可能是Chrome和Firefox上的一个bug,其中传奇和fieldset被替换为元素。
Bugs Reported:
Bug Chrome Bug Firefox
Chrome Bug火狐
A possible Workaround:
A possible workaround would be using
in HTML, and applying in CSS div[role='group'] as selector.
一个可能的解决方案是在HTML中使用
,在CSS div[role='group']中应用作为选择器。
#3
4
In my experience, I've found that neither
, nor , nor can properly use display:flex or inherited properties.
根据我的经验,我发现
,
As others have already mentioned, bugs have been reported. If you want to use flexbox to control ordering (e.g. order:2), then you'd need to wrap the element in a div. If you want flexbox to control actual layout and dimensions, then you may want to consider using a div, instead of the input control (Which stinks, I know).
Might need to use role-group because firefox, chrome and i think safari have a bug with fieldsets apparently. Then the selector in the CSS would simply be